package de.polygonal.motor2.utils 
{
	import de.polygonal.ds.Iterator;
	import de.polygonal.motor2.World;
	import de.polygonal.motor2.collision.shapes.ShapeSkeleton;
	import de.polygonal.motor2.dynamics.RigidBody;	

	/**
	 * @author Michael Baczynski
	 */
	public class ShapeIterator implements Iterator
	{
		private var _bodyList:RigidBody;
		
		private var _body:RigidBody;
		private var _shape:ShapeSkeleton;

		public function ShapeIterator(world:World)
		{
			_bodyList = world.bodyList;
		}

		public function hasNext():Boolean
		{
			return _shape ? true : Boolean(_body.next);
		}
		
		public function next():*
		{
			var s:ShapeSkeleton = _shape;
			if (_shape.next)
				_shape = _shape.next;
			else
			{
				_body = _body.next;
				if (_body) _shape = _shape.next;	
			}
			
			return s;
		}
		
		public function start():void
		{
			_body = _bodyList;
			_shape = _bodyList.shapeList;
		}

		public function get data():*
		{
			return _shape;
		}
		
		public function set data(obj:*):void
		{	
		}
	}
}
